package com.hig.ledger.service.impl;

import java.util.List;

import com.ruoyi.common.annotation.DataScope;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.framework.web.service.TokenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.hig.ledger.mapper.LedgerPipelineMapper;
import com.hig.ledger.domain.LedgerPipeline;
import com.hig.ledger.service.ILedgerPipelineService;

/**
 * 胀压管道清单Service业务层处理
 *
 * @author scp
 * @date 2024-09-22
 */
@Service
public class LedgerPipelineServiceImpl implements ILedgerPipelineService
{
    @Autowired
    private LedgerPipelineMapper ledgerPipelineMapper;
    @Autowired
    private TokenService tokenService;

    /**
     * 查询胀压管道清单
     *
     * @param id 胀压管道清单ID
     * @return 胀压管道清单
     */
    @Override
    public LedgerPipeline selectLedgerPipelineById(Long id)
    {
        return ledgerPipelineMapper.selectLedgerPipelineById(id);
    }

    /**
     * 查询胀压管道清单列表
     *
     * @param ledgerPipeline 胀压管道清单
     * @return 胀压管道清单
     */
    @Override
    @DataScope(deptAlias = "d")
    public List<LedgerPipeline> selectLedgerPipelineList(LedgerPipeline ledgerPipeline)
    {
        return ledgerPipelineMapper.selectLedgerPipelineList(ledgerPipeline);
    }

    /**
     * 新增胀压管道清单
     *
     * @param ledgerPipeline 胀压管道清单
     * @return 结果
     */
    @Override
    public int insertLedgerPipeline(LedgerPipeline ledgerPipeline)
    {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        ledgerPipeline.setCreateBy(loginUser.getUser().getUserName());
        ledgerPipeline.setDeptId(loginUser.getUser().getDeptId());
//        long id = ledgerPipelineMapper.getNextId();
//        ledgerPipeline.setId(id);
        ledgerPipeline.setCreateTime(DateUtils.getNowDate());
        return ledgerPipelineMapper.insertLedgerPipeline(ledgerPipeline);
    }

    /**
     * 修改胀压管道清单
     *
     * @param ledgerPipeline 胀压管道清单
     * @return 结果
     */
    @Override
    public int updateLedgerPipeline(LedgerPipeline ledgerPipeline)
    {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        ledgerPipeline.setUpdateBy(loginUser.getUser().getUserName());
        ledgerPipeline.setUpdateTime(DateUtils.getNowDate());
        return ledgerPipelineMapper.updateLedgerPipeline(ledgerPipeline);
    }

    /**
     * 批量删除胀压管道清单
     *
     * @param ids 需要删除的胀压管道清单ID
     * @return 结果
     */
    @Override
    public int deleteLedgerPipelineByIds(Long[] ids)
    {
        return ledgerPipelineMapper.deleteLedgerPipelineByIds(ids);
    }

    /**
     * 删除胀压管道清单信息
     *
     * @param id 胀压管道清单ID
     * @return 结果
     */
    @Override
    public int deleteLedgerPipelineById(Long id)
    {
        return ledgerPipelineMapper.deleteLedgerPipelineById(id);
    }
}
